<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>申报主体备案</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
    <style type="text/css">
    #corptable td:first-child{
        vertical-align: middle!important;
    }
    .ui-jqgrid-hbox th{
        vertical-align: middle!important;
    }
    </style>
</head>
<body>
<div class="content content_frame">
    <h3 class="mainTitle"><img src="${basePath}/images/icon2.png"/>申报主体备案</h3>
    <br>
    <ul class="contentNav dib-wrap">
        <li class="dib" id="btnSearch" defaultkey='13'>
            <a><i class='fa fa-search'></i>&nbsp;&nbsp;查&nbsp;询 </a>
        </li>
        <li class="dib ">
            <a onclick="ClearAllInput('SearchTable')">
                <i class='fa fa-refresh'></i>&nbsp;&nbsp;重&nbsp;置 </a>
        </li>
        <span name="spanHasAuth">
        <li class="dib">
            <a onclick="addEnt()"><i class='fa fa-plus'></i>&nbsp;&nbsp;新&nbsp;增 </a>
        </li>
        <li class="dib">
            <a onclick="modifyEnt();"><i class='fa fa-edit'></i>&nbsp;&nbsp;修&nbsp;改
            </a>
        </li>
        </span>
    </ul>
    <br/>

    <table class="table1" id="SearchTable" width="100%">
        <colgroup>
            <col width="130">
            <col>
            <col width="130">
            <col>
            <col width="120">
            <col>
            <col width="120">
            <col>
        </colgroup>
        <tr>
            <th class="titleCss">申报主体名称</th>
            <td><input type="text" class="" id="subjectName" placeholder="申报主体名称"
                       datafield="SearchTable.subjectName"></td>
            <th class="titleCss">组织机构代码</th>
            <td><input type="text" class="" id="entOrgCode" placeholder="组织机构代码"
                       datafield="SearchTable.entOrgCode"></td>

            <th class="titleCss">关备案状态</th>
            <td>
                <ui:tsingletableautocomplete
                        keyFieldName="statusCust"
                        valueFieldName="statusCustxxxx"
                        tableName="DICT_ITEM"
                        key="ITEM_KEY"
                        value="ITEM_VALUE"
                        groupId="ENT_DECLARE_CUST_STATUS"
                        defaultKey=""
                        defaultValue=""
                        css=""/>
            </td>
            <th class="titleCss">检备案状态</th>
            <td>
                <ui:tsingletableautocomplete
                        keyFieldName="statusInsp"
                        valueFieldName="statusInspxxxx"
                        tableName="DICT_ITEM"
                        key="ITEM_KEY"
                        value="ITEM_VALUE"
                        groupId="DEC_STATUS_ENT_INSP"
                        defaultKey=""
                        defaultValue=""
                        css=""/>
            </td>
        </tr>
        <tr>
            <th class="titleCss">海关十位编码</th>
            <td>
                <input type="text" datafield="SearchTable.customsId" class=""/>
            </td>
            <th class="titleCss">备案时间</th>
            <td>
                <input type='text' class="Wdate " id="applytimeStart"
                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'applytimeEnd\')}'})"
                       timeformat="YYYY-MM-DD"
                       datafield="SearchTable.applytimeStart"/>
            </td>
            <th class="titleCss">至</th>
            <td>
                <input type='text' class="Wdate " id="applytimeEnd"
                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'applytimeStart\')}'})"
                       timeformat="YYYY-MM-DD" datafield="SearchTable.applytimeEnd"/>
            </td>
            <td></td>
            <td></td>
        </tr>

    </table>
    <div class="cl"></div>
    <br/>
    <table id="corptable">
    </table>
    <div id="corptablePage">
    </div>
</div>

<script type="text/javascript">
    function showDetail(url) {
        location.href = url;
    }

    function urlCode(cellvalue, options, rowObject) {
        cellvalue = cellvalue || '';
        cellvalue = $.trim(cellvalue);

        var url = '${basePath}/entBackup/edit?id=' + rowObject.id;
        return "<a class='btn-link' data-value=\"" + cellvalue + "\" onclick='showDetail(\"" + url + "\")'>" + "<span  style='color:#00acec;cursor: pointer'>" + cellvalue + "</span></a>";
    }

    $(function () {

        //查询
        $("#btnSearch").click(function () {
            var jsonStr = customFormToData("SearchTable");
            $("#corptable").jqGrid('setGridParam', {
                url: $basePath + "/entBackup/page", postData: JSON.parse(jsonStr), page: 1
            }).trigger("reloadGrid"); //重新载入
        });
        $("#corptable").jqGrid({
            datatype: "json",
            url: $basePath + "/entBackup/page",
            colNames: [
                '申报主体名称',
                '组织结构代码',
                '海关十位编码',
                '关备案状态',
                '检备案状态',
                '备案时间',
                '',
                '',
                ''
            ],
            colModel: [
                {name: 'subjectName', index: 'subjectName', formatter: urlCode, width: '150px'},
                {name: 'entOrgCode', index: 'entOrgCode', width: '150px'},
                {name: 'customsId', index: 'customsId', width: '150px'},
                {name: 'statusCustDisplay', index: 'statusCustDisplay', width: '150px'},
                {name: 'statusInspDisplay', index: 'statusInspDisplay', width: '150px'},
                {name: 'applytime', index: 'applytime', width: '150px'},
                {name: 'id', index: 'id', hidden: true},
                {name: 'statusCust', index: 'statusCust', hidden: true},
                {name: 'statusInsp', index: 'statusInsp', hidden: true}
            ],
            height: 'auto',
            shrinkToFit: false,
            autowidth: true,
            autoScroll: true,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
//            rownumbers: true,
            multiselect: true, //是否支持多选
            multiselectWidth: 35,
            viewrecords: true, //是否显示行数
            pager: "#corptablePage", //分页工具栏
            altRows: true,
            altclass: 'someClass',
            sortable: true,
            sortname: "createTime",
            sortorder: "asc",
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                } else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }

                $("#corptable").setGridWidth($(window).width()*0.98);
                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            }
        });
    });

    function addEnt() {
        window.location.href = $basePath + '/entBackup/insert?r=' + Math.random();
    }
    function modifyEnt() {
        var _data = getId("corptable");
        if (_data.length == 1) {
            var _rows = getRows("corptable");
            for (var i in _rows) {
                var _statusCust = _rows[i]['statusCust'];
                var _statusInsp = _rows[i]['statusInsp'];

                if ((_statusCust == 'E1' && _statusInsp == 'E1')
                        || _statusInsp == 'E1' || _statusInsp == '1' || _statusInsp == '4' || _statusInsp == '9') {
                    window.location.href = $basePath + '/entBackup/edit?id=' + _data[0] + "&r=" + Math.random();
                    return;
                }

                layerAlert("对不起只有本地暂存、审核未通过才能修改");
                return;
            }

        } else {
            layerAlert("对不起,您只能选中一条记录");
        }
    }
    function getId(gridId) {
        var selectIDs = $("#" + gridId + "").getGridParam("selarrrow");
        var rows = [];
        var _row;
        for (var rowId in selectIDs) {
            _row = $("#" + gridId + "").jqGrid("getRowData", selectIDs[rowId]);
            rows.push(_row.id);
        }

        return rows;
    }

    function getRows(gridId) {
        var selectIDs = $("#" + gridId + "").getGridParam("selarrrow");
        var rows = [];
        for (var rowId in selectIDs) {
            rows.push($("#" + gridId + "").jqGrid("getRowData", selectIDs[rowId]));
        }

        return rows;
    }

    <%--function deleteEnt() {--%>
    <%--var _data = getId("corptable");--%>
    <%--if (_data.length < 1) {--%>
    <%--showWarningMsg("对不起,请选择要删除的记录", "系统提示", null, null);--%>
    <%--return;--%>
    <%--}--%>

    <%--if (!checkDeleteRows("corptable", ["", "1"])) {--%>
    <%--return false;--%>
    <%--}--%>

    <%--showConfirm("确定要删除选中的记录吗?", "系统提示", function () {--%>

    <%--var _dataStr = "applicationIdZ=" + _data.join("&applicationIdZ=").toString();--%>
    <%--$.ajax({--%>
    <%--type: "post",--%>
    <%--url: '${basePath}/entBackup/delete',--%>
    <%--data: _dataStr,--%>
    <%--success: function () {--%>
    <%--showOKMessage('删除成功!', '', function () {--%>
    <%--var jsonStr = customFormToData("SearchTable");--%>
    <%--$("#corptable").jqGrid('setGridParam', {--%>
    <%--url: $basePath + "/entBackup/page", postData: JSON.parse(jsonStr), page: 1--%>
    <%--}).trigger("reloadGrid"); //重新载入--%>
    <%--});--%>
    <%--},--%>
    <%--error: function () {--%>
    <%--ShowMessages("删除失败", "系统提示", "msgwaring", null, 0);--%>
    <%--}--%>
    <%--});--%>
    <%--});--%>
    <%--}--%>

    <%--function declareEnt() {--%>
    <%--var _rows = getRows("corptable");--%>
    <%--if (_rows.length < 1) {--%>
    <%--showWarningMsg("对不起,请选择要备案的记录", "系统提示", null, null);--%>
    <%--return;--%>
    <%--}--%>

    <%--for (var i in _rows) {--%>
    <%--var _statusC = _rows[i]['sendStatusC'] || '1';--%>
    <%--var _statusI = _rows[i]['sendStatusI'] || '1';--%>
    <%--if (_statusC == '1' && _statusI == '1') {--%>
    <%--continue;--%>
    <%--}--%>

    <%--showWarningMsg("对不起,[" + _rows[i]['companyNameZ'] + "]状态不是本地暂存，不能备案", "系统提示", null, null);--%>
    <%--return;--%>
    <%--}--%>

    <%--var _data = getId("corptable");--%>
    <%--var _dataStr = "applicationIdZ=" + _data.join("&applicationIdZ=").toString();--%>
    <%--$.ajax({--%>
    <%--type: "post",--%>
    <%--url: '${basePath}/entBackup/declare',--%>
    <%--datatype: "json",--%>
    <%--data: _dataStr,--%>
    <%--success: function (result) {--%>
    <%--if (result['code'] + '' == '1') {--%>
    <%--showOKMessage('提交申请成功!', '', function () {--%>
    <%--var jsonStr = customFormToData("SearchTable");--%>
    <%--$("#corptable").jqGrid('setGridParam', {--%>
    <%--url: $basePath + "/entBackup/page", postData: JSON.parse(jsonStr), page: 1--%>
    <%--}).trigger("reloadGrid"); //重新载入--%>
    <%--});--%>
    <%--return;--%>
    <%--}--%>

    <%--showWarningMsg("备案失败" + result['msg'], "系统提示", null, null);--%>
    <%--},--%>
    <%--error: function () {--%>
    <%--ShowMessages("备案失败", "系统提示", "msgwaring", null, 0);--%>
    <%--}--%>
    <%--});--%>
    <%--}--%>
</script>
</body>
</html>
